package com.fms;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class TestUtils
{
	public static JFrame showInFrame(JComponent component)
	{
		JFrame frame = new JFrame();
		frame.setLayout( new BorderLayout());
		frame.add(component, BorderLayout.CENTER);
		frame.pack();
		frame.setVisible(true);
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.setPreferredSize(component.getPreferredSize());
		return frame;
	}
    public static Component find(String name, Container c)
    {
        String currentName = c.getName();
        if(currentName != null)
        {
            if( currentName.equals(name))
            {
                return c;
            }
        }
        for(int i = 0; i < c.getComponentCount(); i++)
        {
            JComponent current = (JComponent)c.getComponent(i);
            if(current != null)
            {
                Component result = find(name , (JComponent)c.getComponent(i));
                if(result != null)
                {
                    return result;
                }
            }
            String componentName = c.getName();
            if(componentName != null)
            {
                if(componentName.equals(name))
                {
                    return c.getComponent(i);
                }
            }
        }
        return null;
    
    }
    public static void printAll( Container c)
    {
        
        for(int i = 0; i < c.getComponentCount(); i++)
        {
            JComponent current = (JComponent)c.getComponent(i);
            if(current != null)
            {
                printAll((JComponent)c.getComponent(i));
                
            }
            String componentName = c.getName();
            if(componentName != null)
            {
                System.out.println(componentName);
            }
        }
    
    }
	public static boolean aboutEqual(double a, double b)
	{
		return Math.abs(a - b) < 0.00001;
	}
}
